/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmProductivityReport.java
 *
 * Created on Oct 2, 2011, 3:02:19 PM
 */
package khmhappointmentsystem;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.Map;
import org.jdesktop.application.Action;

/**
 *
 * @author mbelisle
 */
public class FrmProductivityReport extends javax.swing.JInternalFrame {

    /** Creates new form FrmProductivityReport */
    public FrmProductivityReport() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        calStartDate = new com.toedter.calendar.JDateChooser();
        jLabel4 = new javax.swing.JLabel();
        calEndDate = new com.toedter.calendar.JDateChooser();
        cmdCancel = new javax.swing.JButton();
        cmdReport = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("Physiotherapy Productivity Report");

        jLabel1.setText("Generates a report on the productivity of the");
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText("Physiotherapy Unit.");
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText("Start Date:");
        jLabel3.setName("jLabel3"); // NOI18N

        calStartDate.setName("calStartDate"); // NOI18N

        jLabel4.setText("End Date:");
        jLabel4.setName("jLabel4"); // NOI18N

        calEndDate.setName("calEndDate"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance().getContext().getActionMap(FrmProductivityReport.class, this);
        cmdCancel.setAction(actionMap.get("Cancel")); // NOI18N
        cmdCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/khmhappointmentsystem/resources/cancel.png"))); // NOI18N
        cmdCancel.setText("Cancel");
        cmdCancel.setName("cmdCancel"); // NOI18N

        cmdReport.setAction(actionMap.get("RunReport")); // NOI18N
        cmdReport.setIcon(new javax.swing.ImageIcon(getClass().getResource("/khmhappointmentsystem/resources/ruby.png"))); // NOI18N
        cmdReport.setText("Run Report");
        cmdReport.setName("cmdReport"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(cmdReport)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(cmdCancel))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                        .addComponent(jLabel1)
                        .addComponent(jLabel2)
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel3)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(calStartDate, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGroup(layout.createSequentialGroup()
                            .addComponent(jLabel4)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(calEndDate, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap(38, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(calStartDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(calEndDate, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(cmdCancel)
                    .addComponent(cmdReport))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-276)/2, (screenSize.height-184)/2, 276, 184);
    }// </editor-fold>//GEN-END:initComponents

    @Action
    public void Cancel() {
        this.dispose();
    }

    @Action
    public void RunReport() {
         //create object for date
        DateFormat MDY_Formatter = new SimpleDateFormat("MM-dd-yyyy");

        String startDate = MDY_Formatter.format(calStartDate.getDate());
        String endDate = MDY_Formatter.format(calEndDate.getDate());

        String report = "Physiotherapy_Productivity_Report.jasper";
        String location = java.util.ResourceBundle.getBundle("khmhappointmentsystem.resources/Main").getString("reportFolderLocation");
        report = location + report;

        // Second, create a map of parameters to pass to the report.
        Map parameters = new HashMap();
        parameters.put("startDate", startDate);
        parameters.put("endDate", endDate);
        try
        {
            ReportFill ReportFill = new ReportFill();
            ReportFill.generateReport(report, parameters, Environment.getDbConn(), "Physiotherapy Productivity Report");
        }
        catch (Exception exception)
        {
            exception.printStackTrace();
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private com.toedter.calendar.JDateChooser calEndDate;
    private com.toedter.calendar.JDateChooser calStartDate;
    private javax.swing.JButton cmdCancel;
    private javax.swing.JButton cmdReport;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    // End of variables declaration//GEN-END:variables
}
